package org.streets.eis.setting.validatior;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;

/**
 * 多字段验证
 *
 */
public abstract class FormValidator extends AbstractFormValidator{
	private static final long serialVersionUID = 1L;

	private FormComponent<?>[] formComponents;
	
	private String resourceKey;

	/** 
	 * @param resourceKey	资源的key 
	 * @param formComponents 涉及到的FormComponent列表，提示会在第一个FormComponent上
	 * 
	 */
	public FormValidator(String resourceKey,FormComponent<?>... formComponents){
		this.formComponents = formComponents;
		this.resourceKey = resourceKey;
	}

	public FormComponent<?>[] getDependentFormComponents(){
		return formComponents;
	}

	public void validate(Form<?> form){
		if (!doValidate(formComponents)){
			error(formComponents[0]);
		}
	}
	
	@Override
	protected String resourceKey(){
		return resourceKey;
	}
	
	public String getResourceKey(){
		return resourceKey;
	}

	public abstract boolean doValidate(FormComponent<?>[] formComponents);
	
}
